home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / libx11.lha / libX11 / X11c2p.a < prev    next >
Encoding:
Text File  |  1995-07-27  |  17.9 KB  |  997 lines

  1. ;------------------------------------------------------------------------------
  2. ;
  3. ; 100% systemfriendly ChunkyToPlanar converter for use with intuition
  4. ; screens in applications/games/whatever.
  5. ;
  6. ; Coded in 1994 by Morten Eriksen.
  7. ; Reach me through email: mortene@stud.unit.no.
  8. ;
  9. ; Use and modify as you like - give credit where appropriate.
  10. ;
  11. ; Timings on my A1200 with 68EC020 and 32-bit fastram:
  12. ;
  13. ;   Testcase    Dimensions      This routine             C='s WritePixelArray8
  14. ;
  15. ;    1    320x256x5 -    15 frames (0.30 seconds)    33 frames
  16. ;    2    320x256x8 -    16 frames (0.32 seconds)    51 frames
  17. ;    3    640x512x4 -    63 frames (1.26 seconds)    100 frames
  18. ;    4     1024x1024x1 -    194 frames (3.88 seconds)    101 frames
  19. ;    5    752x578x8 -    88 frames (1.76 seconds)    250 frames
  20. ;
  21. ; Please help me speed up this sucker - the main bottleneck is the
  22. ; 'convert32pixels' subroutine (e.g. in the 3rd testcase, 60 out of
  23. ; 63 frames are spent in this routine). As you can see, it gets worse
  24. ; on less bitplanes (compared to C='s routine) - but on 8-bit bitmaps it's
  25. ; about 3 times as fast. If you improve it, be sure to repost the improved
  26. ; version to Usenet, or send it to me through email.
  27. ;
  28. ;------------------------------------------------------------------------------
  29.     xdef    _ChunkyToPlanarAsm
  30. ;------------------------------------------------------------------------------
  31. ; This routine takes a buffer of chunkybytes and transform it into
  32. ; planar datas, which are directly inserted into the destination BitMap.
  33. ;
  34. ; As a replacement for C='s WritePixelArray8 routine, this one is on average
  35. ; about twice as fast and works directly on bitmaps (instead of RastPorts).
  36. ; All cases handled (any width and height > 0, no alignment restrictions).
  37. ; Works on OCS/ECS/AGA, all Kickstarts and any MC680x0 CPU.
  38. ; The downside is that it does not do clipping and does not work with
  39. ; interleaved bitmaps (support for interleaved bitmaps should be piece of
  40. ; cake to implement, though).
  41. ;------------------------------------------------------------------------------
  42. ;
  43. ; C interface:
  44. ;
  45. ; extern void __asm ChunkyToPlanarAsm(register __a0 struct c2pStruct *);
  46. ;
  47. ; struct c2pStruct
  48. ; {
  49. ;  struct BitMap *bmap;
  50. ;  UWORD startX, startY, width, height;
  51. ;  UBYTE *chunkybuffer;
  52. ; } c2p;
  53. ;
  54. ; c2p.bmap = mybitmap;
  55. ; c2p.startX = x0;
  56. ; c2p.startY = y0;
  57. ; c2p.width = x1 - x0 + 1;
  58. ; c2p.height = y1 - y0 + 1;
  59. ; c2p.chunkybuffer = chunkybytes;
  60. ;
  61. ; ChunkyToPlanarAsm(&c2p);
  62. ; CopySBitMap(mywindow->RPort->Layer);
  63. ;------------------------------------------------------------------------------
  64. ;
  65. ; Assembler interface:
  66. ;
  67. ; In:     a0 - c2p struct.
  68. ; Out:    Nothing.
  69. ;------------------------------------------------------------------------------
  70.  
  71. ; ** BitMap struct **
  72. BytesPerRow    EQU    0    ; UWORD
  73. Rows        EQU    2    ; UWORD
  74. Flags        EQU    4    ; UBYTE
  75. Depth        EQU    5    ; UBYTE
  76. Pad        EQU    6    ; UWORD
  77. Planes        EQU    8    ; PLANEPTRs [8]
  78.  
  79. ; ** c2p struct **
  80.  
  81. bmap        EQU    0    ; struct BitMap *
  82. startX        EQU    4    ; UWORD
  83. startY        EQU    6    ; UWORD
  84. width        EQU    8    ; UWORD
  85. height        EQU    10    ; UWORD
  86. chunkybuffer    EQU    12    ; UBYTE *
  87. ;------------------------------------------------------------------------------
  88.     Section    code,CODE
  89.     
  90. _ChunkyToPlanarAsm:
  91.     movem.l    d2-d7/a2-a6,-(sp)
  92.  
  93.     tst.b    madetable        * need only make bitspreadtable once
  94.     bne.s    table_made
  95.     bsr.w    make_table
  96. table_made
  97.  
  98.     * find number of not bytealigned pixels at left side of frame and
  99.     * the mask to be used
  100.     moveq    #0,d0
  101.     move.w    startX(a0),d0
  102.     andi.w    #%111,d0
  103.     tst.w    d0
  104.     beq.s    leadno
  105.     move.w    d0,d1
  106.     moveq    #8,d0
  107.     sub.w    d1,d0
  108.  
  109.     move.b    #$ff,d1
  110.     lsl.b    d0,d1
  111.     move.b    d1,andval_lead
  112.  
  113. leadno    move.w    d0,leadingbits
  114.  
  115.     move.w    width(a0),d0
  116.     cmp.w    leadingbits,d0
  117.     bhs.s    notsingle
  118.  
  119.     * in case the whole chunkypixels buffer to be inserted fits into
  120.     * a single byte
  121.     move.b    #$80,d1
  122.     subq    #1,d0
  123.     asr.b    d0,d1
  124.     addq    #1,d0
  125.     moveq    #8,d2
  126.     sub.w    leadingbits,d2
  127.     lsr.b    d2,d1
  128.     not.b    d1
  129.     move.b    d1,andval_single
  130.     clr.w    trailingbits
  131.     bra.s    single
  132. notsingle
  133.     clr.b    andval_single
  134.  
  135.     * find number of not bytealigned pixels at right side of frame and
  136.     * the mask to be used
  137.     sub.w    leadingbits,d0
  138.     move.w    d0,d1
  139.     andi.w    #$fff8,d1
  140.     sub.w    d1,d0
  141.     move.w    d0,trailingbits
  142.     move.b    #$ff,d1
  143.     lsr.b    d0,d1
  144.     move.b    d1,andval_trail
  145. single
  146.     * initialize variables to be used (modulo, bytealigned width, etc)
  147.     move.l    bmap(a0),a1
  148.     move.l    chunkybuffer(a0),a3
  149.     moveq    #0,d0
  150.     move.b    Depth(a1),d0
  151.     move.w    d0,depth
  152.     move.w    height(a0),Height
  153.     move.w    width(a0),Width
  154.     move.w    leadingbits,d1
  155.     sub.w    d1,Width
  156.     move.w    trailingbits,d1
  157.     sub.w    d1,Width
  158.     move.w    Width,GWidth
  159.     move.w    BytesPerRow(a1),Modulo
  160.     tst.b    andval_single
  161.     bne.s    singlebyte
  162.     move.w    Width,d0
  163.     lsr.w    #3,d0
  164.     sub.w    d0,Modulo
  165. singlebyte
  166.     tst.w    leadingbits
  167.     beq.s    nolead
  168.     sub.w    #1,Modulo
  169. nolead    tst.w    trailingbits
  170.     beq.s    notrail
  171.     sub.w    #1,Modulo
  172. notrail
  173.  
  174.     * find initial offset in bytes into bitmap given by (startX, startY)
  175.     moveq    #0,d0
  176.     move.w    startX(a0),d0
  177.     lsr.w    #3,d0
  178.     move.w    startY(a0),d1
  179.     tst.w    d1
  180.     beq.s    line0
  181.     moveq    #0,d2
  182.     move.w    BytesPerRow(a1),d2
  183.     subq    #1,d1
  184. makeoffset
  185.     add.l    d2,d0
  186.     dbra    d1,makeoffset
  187. line0
  188.     move.l    d0,a2
  189.  
  190.     * find jumpaddress for planar data insertion into bitmap
  191.     * (depending on bitmap depth)
  192.     move.l    a1,a6
  193.     add.l    #Planes,a6
  194.     lea    insertpointerslong,a4
  195.     lea    insertpointers,a5
  196.     moveq    #0,d7
  197.     move.w    depth,d7
  198.     lsl.w    #2,d7
  199.     add.l    d7,a6
  200.     move.l    a6,planepointerspointer
  201.     subq    #4,d7
  202.     add.l    d7,a4
  203.     add.l    d7,a5
  204.     move.l    (a4),insertpointerlong
  205.     move.l    (a5),insertpointer
  206.  
  207.     lea    c2p,a4
  208.  
  209.     ; a0 - c2p struct, a1 - bmap,
  210.     ; a2 - offset from Planes pointer, a3 - chunkybuffer
  211.     ; a4 - bitspread table
  212.  
  213. convertlines
  214.     * check if whole width fits into a single byte and take
  215.     * appropriate action if this is the case
  216.     tst.b    andval_single
  217.     beq.s    testlead
  218.     bsr.w    insertsinglebytebits
  219.     bra.w    trailno
  220.  
  221. testlead
  222.     * is the frame _not_ left bytealigned ?
  223.     tst.w    leadingbits
  224.     beq.b    convert8pixels
  225.     bsr.w    insertleadingbits
  226.  
  227. convert8pixels
  228.     * done?
  229.     tst.w    Width
  230.     beq.s    rowdone
  231.  
  232.     * check if we can do a speedier 32 pixels in one go conversion...
  233.     cmp.w    #32,Width
  234.     blo.s    nolong
  235.     * test odd/even address to be compatible with 68000 aswell *
  236.     move.l    Planes(a1),d0
  237.     add.l    a2,d0
  238.     btst    #0,d0
  239.     bne.s    nolong
  240.     bsr.w    convert32pixels
  241.     sub.w    #32,Width
  242.     addq    #4,a2
  243.     bra.s    convert8pixels
  244.  
  245. nolong    * ...rather than the slower 8 pixel conversion
  246.     moveq    #0,d0
  247.     moveq    #0,d4
  248.     moveq    #8-1,d1
  249. convert8bytes
  250.     * find correct bitspreadtable offset -> a4 *
  251.     moveq    #0,d2
  252.     move.b    (a3)+,d2
  253.     lsl.w    #3,d2
  254.  
  255.     * insert bitrow *
  256.     add.l    d0,d0
  257.     or.l    (a4,d2.w),d0
  258.     addq    #4,d2
  259.     add.l    d4,d4
  260.     or.l    (a4,d2.w),d4
  261.  
  262.     dbra    d1,convert8bytes
  263.  
  264.     * spread bits to all registers *
  265.     move.b    d0,d3
  266.     lsr.w    #8,d0
  267.     move.b    d0,d2
  268.     swap    d0
  269.     move.b    d0,d1
  270.     lsr.w    #8,d0
  271.  
  272.     move.b    d4,d7
  273.     lsr.w    #8,d4
  274.     move.b    d4,d6
  275.     swap    d4
  276.     move.b    d4,d5
  277.     lsr.w    #8,d4
  278.  
  279.     cmp.w    #8,depth
  280.     beq.s    its8
  281.     move.l    a2,d7
  282. its8    move.l    planepointerspointer(pc),a6
  283.     move.l    insertpointer(pc),a5
  284.     jsr    (a5)
  285.  
  286.     addq    #1,a2
  287.     subq    #8,Width
  288.     bra.w    convert8pixels
  289.  
  290. rowdone
  291.     * are there any non bytealigned pixels remaining at the right side
  292.     * of the frame?
  293.     tst.w    trailingbits
  294.     beq.b    trailno
  295.     bsr.w    inserttrailingbits
  296.  
  297. trailno    move.w    GWidth,Width
  298.     add.w    Modulo,a2
  299.     subq    #1,Height
  300.     tst.w    Height
  301.     bne.w    convertlines
  302.  
  303.     movem.l    (sp)+,d2-d7/a2-a6
  304.     rts
  305. ;------------------------------------------------------------------------------
  306. insertdata:    * insert converted 8 pixels c->p data into the bitmap
  307. plane8    move.l    -(a6),a5
  308.     add.l    a2,a5
  309.     move.b    d7,(a5)
  310.     move.l    a2,d7
  311. plane7    move.l    -(a6),a5
  312.     move.b    d6,(a5,d7.l)
  313. plane6    move.l    -(a6),a5
  314.     move.b    d5,(a5,d7.l)
  315. plane5    move.l    -(a6),a5
  316.     move.b    d4,(a5,d7.l)
  317. plane4    move.l    -(a6),a5
  318.     move.b    d3,(a5,d7.l)
  319. plane3    move.l    -(a6),a5
  320.     move.b    d2,(a5,d7.l)
  321. plane2    move.l    -(a6),a5
  322.     move.b    d1,(a5,d7.l)
  323. plane1    move.l    -(a6),a5
  324.     move.b    d0,(a5,d7.l)
  325.     rts
  326. ;------------------------------------------------------------------------------
  327. insertdatalong:    * insert converted 32 pixels c->p data into the bitmap
  328. plane8l    move.l    -(a6),a5
  329.     add.l    a2,a5
  330.     move.l    d7,(a5)
  331.     move.l    a2,d7
  332. plane7l    move.l    -(a6),a5
  333.     move.l    d6,(a5,d7.l)
  334. plane6l    move.l    -(a6),a5
  335.     move.l    d5,(a5,d7.l)
  336. plane5l    move.l    -(a6),a5
  337.     move.l    d4,(a5,d7.l)
  338. plane4l    move.l    -(a6),a5
  339.     move.l    d3,(a5,d7.l)
  340. plane3l    move.l    -(a6),a5
  341.     move.l    d2,(a5,d7.l)
  342. plane2l    move.l    -(a6),a5
  343.     move.l    d1,(a5,d7.l)
  344. plane1l    move.l    -(a6),a5
  345.     move.l    d0,(a5,d7.l)
  346.     rts
  347. ;------------------------------------------------------------------------------
  348. insertpointer        dc.l    0
  349. insertpointerlong    dc.l    0
  350. planepointerspointer    dc.l    0
  351. ;------------------------------------------------------------------------------
  352. convert32pixels:
  353.     * convert 4 * 8 = 32 pixels in one go
  354.     lea    buffer+32,a5
  355.  
  356.     moveq    #4-1,d3
  357. eachlong
  358.     moveq    #0,d2
  359.     move.b    (a3)+,d2
  360.     lsl.w    #3,d2
  361.     movem.l    (a4,d2.w),d0/d4
  362.  
  363.     moveq    #0,d2
  364.     move.b    (a3)+,d2
  365.     lsl.w    #3,d2
  366.     add.l    d0,d0
  367.     or.l    (a4,d2.w),d0
  368.     add.l    d4,d4
  369.     or.l    4(a4,d2.w),d4
  370.  
  371.     moveq    #0,d2
  372.     move.b    (a3)+,d2
  373.     lsl.w    #3,d2
  374.     add.l    d0,d0
  375.     or.l    (a4,d2.w),d0
  376.     add.l    d4,d4
  377.     or.l    4(a4,d2.w),d4
  378.  
  379.     moveq    #0,d2
  380.     move.b    (a3)+,d2
  381.     lsl.w    #3,d2
  382.     add.l    d0,d0
  383.     or.l    (a4,d2.w),d0
  384.     add.l    d4,d4
  385.     or.l    4(a4,d2.w),d4
  386.  
  387.     moveq    #0,d2
  388.     move.b    (a3)+,d2
  389.     lsl.w    #3,d2
  390.     add.l    d0,d0
  391.     or.l    (a4,d2.w),d0
  392.     add.l    d4,d4
  393.     or.l    4(a4,d2.w),d4
  394.  
  395.     moveq    #0,d2
  396.     move.b    (a3)+,d2
  397.     lsl.w    #3,d2
  398.     add.l    d0,d0
  399.     or.l    (a4,d2.w),d0
  400.     add.l    d4,d4
  401.     or.l    4(a4,d2.w),d4
  402.  
  403.     moveq    #0,d2
  404.     move.b    (a3)+,d2
  405.     lsl.w    #3,d2
  406.     add.l    d0,d0
  407.     or.l    (a4,d2.w),d0
  408.     add.l    d4,d4
  409.     or.l    4(a4,d2.w),d4
  410.  
  411.     moveq    #0,d2
  412.     move.b    (a3)+,d2
  413.     lsl.w    #3,d2
  414.     add.l    d0,d0
  415.     or.l    (a4,d2.w),d0
  416.     add.l    d4,d4
  417.     or.l    4(a4,d2.w),d4
  418.  
  419.     * push temporary converted data in buffer
  420.     movem.l    d0/d4,-(a5)
  421.     dbra    d3,eachlong
  422.  
  423.     * buffer now looks like this:
  424.     * d00 d10
  425.     * d20 d30
  426.     * d40 d50
  427.     * d60 d70
  428.     * d01 d11
  429.     * d21 d31
  430.     * d41 d51
  431.     * d61 d71
  432.     * d02 d12
  433.     * d22 d32
  434.     * d42 d52
  435.     * d62 d72
  436.     * d03 d13
  437.     * d23 d33
  438.     * d43 d53
  439.     * d63 d73
  440.     * ...where e.g. d43 means most significant byte (#3) in dataregister 4
  441.  
  442.     * now pop the converted data from the buffer and into the
  443.     * dataregisters
  444.     add.l    #4*2*4,a5
  445.  
  446.     move.l    -(a5),d4
  447.     move.b    d4,d7
  448.     lsr.w    #8,d4
  449.     move.b    d4,d6
  450.     swap    d4
  451.     move.b    d4,d5
  452.     lsr.w    #8,d4
  453.  
  454.     move.l    -(a5),d0
  455.     move.b    d0,d3
  456.     lsr.w    #8,d0
  457.     move.b    d0,d2
  458.     swap    d0
  459.     move.b    d0,d1
  460.     lsr.w    #8,d0
  461.  
  462.     lsl.w    #8,d7
  463.     move.b    -1(a5),d7
  464.     lsl.w    #8,d6
  465.     move.b    -2(a5),d6
  466.     lsl.w    #8,d5
  467.     move.b    -3(a5),d5
  468.     lsl.w    #8,d4
  469.     move.b    -4(a5),d4
  470.     lsl.w    #8,d3
  471.     move.b    -5(a5),d3
  472.     lsl.w    #8,d2
  473.     move.b    -6(a5),d2
  474.     lsl.w    #8,d1
  475.     move.b    -7(a5),d1
  476.     lsl.w    #8,d0
  477.     move.b    -8(a5),d0
  478.  
  479.     swap    d0
  480.     swap    d1
  481.     swap    d2
  482.     swap    d3
  483.     swap    d4
  484.     swap    d5
  485.     swap    d6
  486.     swap    d7
  487.  
  488.     subq    #8,a5
  489.  
  490.     move.w    -(a5),d6
  491.     move.b    d6,d7
  492.     lsr.w    #8,d6
  493.     move.w    -(a5),d4
  494.     move.b    d4,d5
  495.     lsr.w    #8,d4
  496.     move.w    -(a5),d2
  497.     move.b    d2,d3
  498.     lsr.w    #8,d2
  499.     move.w    -(a5),d0
  500.     move.b    d0,d1
  501.     lsr.w    #8,d0
  502.  
  503.     lsl.w    #8,d7
  504.     move.b    -1(a5),d7
  505.     lsl.w    #8,d6
  506.     move.b    -2(a5),d6
  507.     lsl.w    #8,d5
  508.     move.b    -3(a5),d5
  509.     lsl.w    #8,d4
  510.     move.b    -4(a5),d4
  511.     lsl.w    #8,d3
  512.     move.b    -5(a5),d3
  513.     lsl.w    #8,d2
  514.     move.b    -6(a5),d2
  515.     lsl.w    #8,d1
  516.     move.b    -7(a5),d1
  517.     lsl.w    #8,d0
  518.     move.b    -8(a5),d0
  519.  
  520.     * insert the converted c->p data into the bitmap
  521.     cmp.w    #8,depth
  522.     beq.b    its8x
  523.     move.l    a2,d7
  524. its8x    move.l    planepointerspointer(pc),a6
  525.     move.l    insertpointerlong(pc),a5
  526.     jsr    (a5)
  527.     rts
  528. ;------------------------------------------------------------------------------
  529. insertleadingbits:
  530.     moveq    #0,d0
  531.     moveq    #0,d4
  532.     move.w    leadingbits,d1
  533.     subq    #1,d1
  534. convertleadingbits
  535.     * find correct bitspreadtable offset -> a4 *
  536.     moveq    #0,d2
  537.     move.b    (a3)+,d2
  538.     lsl.w    #3,d2
  539.  
  540.     * insert bitrow *
  541.     add.l    d0,d0
  542.     or.l    (a4,d2.w),d0
  543.     addq    #4,d2
  544.     add.l    d4,d4
  545.     or.l    (a4,d2.w),d4
  546.  
  547.     dbra    d1,convertleadingbits
  548.  
  549.     * spread bits to all registers *
  550.     move.b    d0,d3
  551.     lsr.w    #8,d0
  552.     move.b    d0,d2
  553.     swap    d0
  554.     move.b    d0,d1
  555.     lsr.w    #8,d0
  556.  
  557.     move.b    d4,d7
  558.     lsr.w    #8,d4
  559.     move.b    d4,d6
  560.     swap    d4
  561.     move.b    d4,d5
  562.     lsr.w    #8,d4
  563.  
  564.     movem.l    a0-a1/a3,-(sp)
  565.  
  566.     move.w    depth,a0
  567.     addq    #Planes,a1
  568.  
  569.     * read and mix in the data from the bitmap with the converted data
  570. planel0    move.w    d7,-(sp)
  571.     move.l    (a1),a3
  572.     add.l    a2,a3
  573.     move.b    (a3),d7
  574.     and.b    andval_lead,d7
  575.     or.b    d7,d0
  576.     move.w    (sp)+,d7
  577.     move.w    d0,-(sp)
  578.  
  579.     subq    #1,a0
  580.     cmp.w    #0,a0
  581.     beq.w    doneplanes
  582. planel1    addq    #4,a1
  583.     move.l    (a1),a3
  584.     add.l    a2,a3
  585.     move.b    (a3),d0
  586.     and.b    andval_lead,d0
  587.     or.b    d0,d1
  588.  
  589.     subq    #1,a0
  590.     cmp.w    #0,a0
  591.     beq.w    doneplanes
  592. planel2    addq    #4,a1
  593.     move.l    (a1),a3
  594.     add.l    a2,a3
  595.     move.b    (a3),d0
  596.     and.b    andval_lead,d0
  597.     or.b    d0,d2
  598.  
  599.     subq    #1,a0
  600.     cmp.w    #0,a0
  601.     beq.s    doneplanes
  602. planel3    addq    #4,a1
  603.     move.l    (a1),a3
  604.     add.l    a2,a3
  605.     move.b    (a3),d0
  606.     and.b    andval_lead,d0
  607.     or.b    d0,d3
  608.  
  609.     subq    #1,a0
  610.     cmp.w    #0,a0
  611.     beq.s    doneplanes
  612. planel4    addq    #4,a1
  613.     move.l    (a1),a3
  614.     add.l    a2,a3
  615.     move.b    (a3),d0
  616.     and.b    andval_lead,d0
  617.     or.b    d0,d4
  618.  
  619.     subq    #1,a0
  620.     cmp.w    #0,a0
  621.     beq.s    doneplanes
  622. planel5    addq    #4,a1
  623.     move.l    (a1),a3
  624.     add.l    a2,a3
  625.     move.b    (a3),d0
  626.     and.b    andval_lead,d0
  627.     or.b    d0,d5
  628.  
  629.     subq    #1,a0
  630.     cmp.w    #0,a0
  631.     beq.s    doneplanes
  632. planel6    addq    #4,a1
  633.     move.l    (a1),a3
  634.     add.l    a2,a3
  635.     move.b    (a3),d0
  636.     and.b    andval_lead,d0
  637.     or.b    d0,d6
  638.  
  639.     subq    #1,a0
  640.     cmp.w    #0,a0
  641.     beq.s    doneplanes
  642. planel7    addq    #4,a1
  643.     move.l    (a1),a3
  644.     add.l    a2,a3
  645.     move.b    (a3),d0
  646.     and.b    andval_lead,d0
  647.     or.b    d0,d7
  648.  
  649. doneplanes
  650.     move.w    (sp)+,d0
  651.     movem.l    (sp)+,a0-a1/a3
  652.     
  653.     cmp.w    #8,depth
  654.     beq.s    its8l
  655.     move.l    a2,d7
  656. its8l    move.l    planepointerspointer(pc),a6
  657.     move.l    insertpointer(pc),a5
  658.     jsr    (a5)
  659.     addq    #1,a2
  660.     rts
  661. ;------------------------------------------------------------------------------
  662. inserttrailingbits:
  663.     moveq    #0,d0
  664.     moveq    #0,d4
  665.     move.w    trailingbits,d1
  666.     subq    #1,d1
  667. converttrailingbits
  668.     * find correct bitspreadtable offset -> a4 *
  669.     moveq    #0,d2
  670.     move.b    (a3)+,d2
  671.     lsl.w    #3,d2
  672.  
  673.     * insert bitrow *
  674.     add.l    d0,d0
  675.     or.l    (a4,d2.w),d0
  676.     addq    #4,d2
  677.     add.l    d4,d4
  678.     or.l    (a4,d2.w),d4
  679.  
  680.     dbra    d1,converttrailingbits
  681.  
  682.     moveq    #8,d1
  683.     sub.w    trailingbits,d1
  684.     lsl.l    d1,d0
  685.     lsl.l    d1,d4
  686.     
  687.     * spread bits to all registers *
  688.     move.b    d0,d3
  689.     lsr.w    #8,d0
  690.     move.b    d0,d2
  691.     swap    d0
  692.     move.b    d0,d1
  693.     lsr.w    #8,d0
  694.  
  695.     move.b    d4,d7
  696.     lsr.w    #8,d4
  697.     move.b    d4,d6
  698.     swap    d4
  699.     move.b    d4,d5
  700.     lsr.w    #8,d4
  701.  
  702.     movem.l    a0-a1/a3,-(sp)
  703.  
  704.     move.w    depth,a0
  705.     addq    #Planes,a1
  706.  
  707.     * read and mix in the data from the bitmap with the converted data
  708. planet0    move.w    d7,-(sp)
  709.     move.l    (a1),a3
  710.     add.l    a2,a3
  711.     move.b    (a3),d7
  712.     and.b    andval_trail,d7
  713.     or.b    d7,d0
  714.     move.w    (sp)+,d7
  715.     move.w    d0,-(sp)
  716.  
  717.     subq    #1,a0
  718.     cmp.w    #0,a0
  719.     beq.w    done_planes
  720. planet1    addq    #4,a1
  721.     move.l    (a1),a3
  722.     add.l    a2,a3
  723.     move.b    (a3),d0
  724.     and.b    andval_trail,d0
  725.     or.b    d0,d1
  726.  
  727.     subq    #1,a0
  728.     cmp.w    #0,a0
  729.     beq.w    done_planes
  730. planet2    addq    #4,a1
  731.     move.l    (a1),a3
  732.     add.l    a2,a3
  733.     move.b    (a3),d0
  734.     and.b    andval_trail,d0
  735.     or.b    d0,d2
  736.  
  737.     subq    #1,a0
  738.     cmp.w    #0,a0
  739.     beq.s    done_planes
  740. planet3    addq    #4,a1
  741.     move.l    (a1),a3
  742.     add.l    a2,a3
  743.     move.b    (a3),d0
  744.     and.b    andval_trail,d0
  745.     or.b    d0,d3
  746.  
  747.     subq    #1,a0
  748.     cmp.w    #0,a0
  749.     beq.s    done_planes
  750. planet4    addq    #4,a1
  751.     move.l    (a1),a3
  752.     add.l    a2,a3
  753.     move.b    (a3),d0
  754.     and.b    andval_trail,d0
  755.     or.b    d0,d4
  756.  
  757.     subq    #1,a0
  758.     cmp.w    #0,a0
  759.     beq.s    done_planes
  760. planet5    addq    #4,a1
  761.     move.l    (a1),a3
  762.     add.l    a2,a3
  763.     move.b    (a3),d0
  764.     and.b    andval_trail,d0
  765.     or.b    d0,d5
  766.  
  767.     subq    #1,a0
  768.     cmp.w    #0,a0
  769.     beq.s    done_planes
  770. planet6    addq    #4,a1
  771.     move.l    (a1),a3
  772.     add.l    a2,a3
  773.     move.b    (a3),d0
  774.     and.b    andval_trail,d0
  775.     or.b    d0,d6
  776.  
  777.     subq    #1,a0
  778.     cmp.w    #0,a0
  779.     beq.s    done_planes
  780. planet7    addq    #4,a1
  781.     move.l    (a1),a3
  782.     add.l    a2,a3
  783.     move.b    (a3),d0
  784.     and.b    andval_trail,d0
  785.     or.b    d0,d7
  786.  
  787. done_planes
  788.     move.w    (sp)+,d0
  789.     movem.l    (sp)+,a0-a1/a3
  790.     
  791.     cmp.w    #8,depth
  792.     beq.s    its8t
  793.     move.l    a2,d7
  794. its8t    move.l    planepointerspointer(pc),a6
  795.     move.l    insertpointer(pc),a5
  796.     jsr    (a5)
  797.     addq    #1,a2
  798.     rts
  799. ;------------------------------------------------------------------------------
  800. insertsinglebytebits:
  801.     moveq    #0,d0
  802.     moveq    #0,d4
  803.     move.w    width(a0),d1
  804.     subq    #1,d1
  805. convertsinglebytebits
  806.     * find correct bitspreadtable offset -> a4 *
  807.     moveq    #0,d2
  808.     move.b    (a3)+,d2
  809.     lsl.w    #3,d2
  810.  
  811.     * insert bitrow *
  812.     add.l    d0,d0
  813.     or.l    (a4,d2.w),d0
  814.     addq    #4,d2
  815.     add.l    d4,d4
  816.     or.l    (a4,d2.w),d4
  817.  
  818.     dbra    d1,convertsinglebytebits
  819.  
  820.     moveq    #0,d1
  821.     move.w    leadingbits,d1
  822.     sub.w    width(a0),d1
  823.     lsl.l    d1,d0
  824.     lsl.l    d1,d4
  825.     
  826.     * spread bits to all registers *
  827.     move.b    d0,d3
  828.     lsr.w    #8,d0
  829.     move.b    d0,d2
  830.     swap    d0
  831.     move.b    d0,d1
  832.     lsr.w    #8,d0
  833.  
  834.     move.b    d4,d7
  835.     lsr.w    #8,d4
  836.     move.b    d4,d6
  837.     swap    d4
  838.     move.b    d4,d5
  839.     lsr.w    #8,d4
  840.  
  841.     movem.l    a0-a1/a3,-(sp)
  842.  
  843.     move.w    depth,a0
  844.     addq    #Planes,a1
  845.  
  846.     * read and mix in the data from the bitmap with the converted data
  847. planes0    move.w    d7,-(sp)
  848.     move.l    (a1),a3
  849.     add.l    a2,a3
  850.     move.b    (a3),d7
  851.     and.b    andval_single,d7
  852.     or.b    d7,d0
  853.     move.w    (sp)+,d7
  854.     move.w    d0,-(sp)
  855.  
  856.     subq    #1,a0
  857.     cmp.w    #0,a0
  858.     beq.w    done__planes
  859. planes1    addq    #4,a1
  860.     move.l    (a1),a3
  861.     add.l    a2,a3
  862.     move.b    (a3),d0
  863.     and.b    andval_single,d0
  864.     or.b    d0,d1
  865.  
  866.     subq    #1,a0
  867.     cmp.w    #0,a0
  868.     beq.w    done__planes
  869. planes2    addq    #4,a1
  870.     move.l    (a1),a3
  871.     add.l    a2,a3
  872.     move.b    (a3),d0
  873.     and.b    andval_single,d0
  874.     or.b    d0,d2
  875.  
  876.     subq    #1,a0
  877.     cmp.w    #0,a0
  878.     beq.s    done__planes
  879. planes3    addq    #4,a1
  880.     move.l    (a1),a3
  881.     add.l    a2,a3
  882.     move.b    (a3),d0
  883.     and.b    andval_single,d0
  884.     or.b    d0,d3
  885.  
  886.     subq    #1,a0
  887.     cmp.w    #0,a0
  888.     beq.s    done__planes
  889. planes4    addq    #4,a1
  890.     move.l    (a1),a3
  891.     add.l    a2,a3
  892.     move.b    (a3),d0
  893.     and.b    andval_single,d0
  894.     or.b    d0,d4
  895.  
  896.     subq    #1,a0
  897.     cmp.w    #0,a0
  898.     beq.s    done__planes
  899. planes5    addq    #4,a1
  900.     move.l    (a1),a3
  901.     add.l    a2,a3
  902.     move.b    (a3),d0
  903.     and.b    andval_single,d0
  904.     or.b    d0,d5
  905.  
  906.     subq    #1,a0
  907.     cmp.w    #0,a0
  908.     beq.s    done__planes
  909. planes6    addq    #4,a1
  910.     move.l    (a1),a3
  911.     add.l    a2,a3
  912.     move.b    (a3),d0
  913.     and.b    andval_single,d0
  914.     or.b    d0,d6
  915.  
  916.     subq    #1,a0
  917.     cmp.w    #0,a0
  918.     beq.s    done__planes
  919. planes7    addq    #4,a1
  920.     move.l    (a1),a3
  921.     add.l    a2,a3
  922.     move.b    (a3),d0
  923.     and.b    andval_single,d0
  924.     or.b    d0,d7
  925.  
  926. done__planes
  927.     move.w    (sp)+,d0
  928.     movem.l    (sp)+,a0-a1/a3
  929.     
  930.     cmp.w    #8,depth
  931.     beq.s    its8s
  932.     move.l    a2,d7
  933. its8s    move.l    planepointerspointer(pc),a6
  934.     move.l    insertpointer(pc),a5
  935.     jsr    (a5)
  936.     addq    #1,a2
  937.     rts
  938. ;------------------------------------------------------------------------------
  939. * makes the bitspread table *
  940. * Do not destroy a0! *
  941. make_table:
  942.     lea    c2p,a1
  943.     moveq    #0,d0
  944. more_table
  945.     move.b    d0,d1
  946.  
  947.     moveq    #8-1,d2
  948. byteloop
  949.     btst    #0,d1
  950.     beq.s    zero
  951.     move.b    #1,(a1)+
  952.     bra.s    one
  953. zero    clr.b    (a1)+
  954. one    lsr.b    #1,d1
  955.     dbra    d2,byteloop
  956.  
  957.     addq    #1,d0
  958.     cmp.w    #256,d0
  959.     beq.s    table_done
  960.     bra.s    more_table
  961. table_done
  962.     move.b    #1,madetable    
  963.     rts
  964. ;------------------------------------------------------------------------------
  965.     Section    variables,DATA
  966.  
  967. depth    dc.w    0
  968. Width    dc.w    0
  969. GWidth    dc.w    0
  970. Height    dc.w    0
  971. Modulo    dc.w    0
  972. insertpointers
  973.     dc.l    plane1,plane2,plane3,plane4,plane5,plane6,plane7,plane8
  974. insertpointerslong
  975.     dc.l    plane1l,plane2l,plane3l,plane4l,plane5l,plane6l,plane7l,plane8l
  976. leadingbits
  977.     dc.w    0
  978. trailingbits
  979.     dc.w    0
  980. madetable
  981.     dc.b    0
  982. andval_lead
  983.     dc.b    0
  984. andval_trail
  985.     dc.b    0
  986. andval_single
  987.     dc.b    0
  988. ;------------------------------------------------------------------------------
  989.     Section    tables,BSS    
  990.  
  991. * bitspread table *
  992. c2p    ds.b    256*8
  993. * temporary buffer *
  994. buffer    ds.b    32
  995. ;------------------------------------------------------------------------------
  996.     End
  997.